package com.dgut.cbd.finalexp.myController;

import com.dgut.cbd.finalexp.dao.RecordDao;
import com.dgut.cbd.finalexp.dao.UserDao;
import com.dgut.cbd.finalexp.dto.R;
import com.dgut.cbd.finalexp.dto.RecordInfo;
import com.dgut.cbd.finalexp.entity.Record;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Program: finalexp
 * @Description:
 * @Author: cbd
 * @Create: 2021-06-21
 * @Version: 1.0.0
 **/
@Controller
public class AdminController {

    @RequestMapping("/admin/login")
    public String loginPage(){
        return "admin/login";
    }

    @RequestMapping("/admin/manage")
    public String recordPage(){
        return "admin/manage";
    }

    @RestController
    static class AdminRestController{

        @Autowired
        UserDao userDao;

        @Autowired
        RecordDao recordDao;

        @RequestMapping("/admin/getRecordWithSelector")
        public R getAllRecordBySelector(@RequestBody RecordInfo recordInfo){

            if (recordInfo.getDate()!=null){
                recordInfo.getDate().setHours(0);
                recordInfo.getDate().setMinutes(0);
                recordInfo.getDate().setSeconds(0);
            }

            List<Record> registerInfos = recordDao.selectRecordsByRegisterInfo(recordInfo);
            return R.success(registerInfos);
        }

    }

}
